const _store: { [proName: string]: { time: number; data: any } } = {};

export const getDataByStore = (key: string) => {
  const value = _store[key];
  const date = new Date();
  if (value) {
    const { time, data } = value;
    if (date.getTime() < time) {
      return data;
    } else {
      delete _store[key];
    }
  }
  return null;
};

export const setData2Store = ({
  time,
  data,
  key
}: {
  time: number;
  data: any;
  key: string;
}) => {
  const date = new Date();
  _store[key] = { time: date.getTime() + time, data };
  setTimeout(() => {
    delete _store[key];
  }, time);
};
